Skip to content

Conversation

@YairRand
Copy link
Contributor

Change lookAheadNotOpenBracePattern to allow selectors to match "" patterns (eg [class="span"]) and selectors with comments interspersed. This fixes issue #35, where text before either comments or attribute selectors using double quotes were not being considered part of the selector, and having text flipped as though they were part of rules. (Eg .right [class="span"] { float: right; } was flipped to .left .)

Change lookAheadNotOpenBracePattern to allow selectors to match "" patterns (eg [class="span"]) and selectors with comments interspersed. This fixes issue wikimedia#35, where text before either comments or attribute selectors using double quotes were not being considered part of the selector, and having text flipped as though they were part of rules. (Eg `.right [class="span"] { float: right; }` was flipped to `.left` .)
@Krinkle Krinkle self-assigned this Feb 11, 2018
@Krinkle
Copy link
Member

Krinkle commented Feb 11, 2018

Thanks!

Add tests for "leave class names alone" to work when selector includes either comments or attribute selectors with double quotes.
colorPattern = '(#?' + nmcharPattern + '+|(?:rgba?|hsla?)\\([ \\d.,%-]+\\))',
urlCharsPattern = '(?:' + urlSpecialCharsPattern + '|' + nonAsciiPattern + '|' + escapePattern + ')*',
lookAheadNotLetterPattern = '(?![a-zA-Z])',
lookAheadNotOpenBracePattern = '(?!(' + nmcharPattern + '|\\r?\\n|\\s|#|\\:|\\.|\\,|\\+|>|\\(|\\)|\\[|\\]|=|\\*=|~=|\\^=|\'[^\']*\'])*?{)',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain the removal of the closing square bracket ] from the original line? Actually, I'm unsure as to why it what was there, but would be good to confirm whether its removal was important to this change, or just clean up, or something else.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't actually remember the reason for that, but I can guess.

Presumably, the original purpose of the ] was to ensure that the quotes were specifically part of simple attribute selector values, like [class='span'] ('] at the end), which are by far the most common use of quotes in selectors. However, this prevents it from matching other types of quotes in selectors, such as :lang("en") and [class='span' i]. (Currently, both have some browser support and are in Working Draft state of the spec.)

@Krinkle
Copy link
Member

Krinkle commented Aug 23, 2020

Benchmark

Before:

nobody@0c6fcfefbc0c:/cssjanus$ node test/bench.js 
Bench mediawiki: 3229 op/s in 0.3s
Bench ooui: 645 op/s in 1.5s

nobody@0c6fcfefbc0c:/cssjanus$ node test/bench.js 
Bench mediawiki: 3176 op/s in 0.3s
Bench ooui: 636 op/s in 1.6s

nobody@0c6fcfefbc0c:/cssjanus$ node test/bench.js 
Bench mediawiki: 3198 op/s in 0.3s
Bench ooui: 637 op/s in 1.6s

After:

nobody@0c6fcfefbc0c:/cssjanus$ node test/bench.js 
Bench mediawiki: 3140 op/s in 0.3s
Bench ooui: 630 op/s in 1.6s

nobody@0c6fcfefbc0c:/cssjanus$ node test/bench.js 
Bench mediawiki: 3197 op/s in 0.3s
Bench ooui: 644 op/s in 1.6s

nobody@0c6fcfefbc0c:/cssjanus$ node test/bench.js 
Bench mediawiki: 3243 op/s in 0.3s
Bench ooui: 644 op/s in 1.6s

@Krinkle Krinkle closed this in b9aac27 Aug 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants